package com.daigoudao.system;

import java.io.File;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 系统启动的入口
 * 
 * @author yangfeng
 * 
 */
public class StartupListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent contextEvent) {
		// 干掉
	}

	@Override
	public void contextInitialized(ServletContextEvent contextEvent) {
		ServletContext context = contextEvent.getServletContext();
		String configPath = System.getProperty("conf");
		if (configPath == null) {
			System.out
					.println("java vm parameters not found!, please add -Dconf=xxx to VM parameters!");
			System.exit(-1);
		}

		
		String systemName = context.getInitParameter(
				"systemName");
		// 实际的配置跟目录
		configPath = configPath + File.separator + systemName;

		File file = new File(configPath);

		if (file.exists() && file.isDirectory()) {
			ServerContext.init(configPath);
		} else {
			System.out.println("You provided ConfigPath error!" + configPath);
			System.exit(-1);
		}
	}

}
